import { Color, log } from "@/contrib";
import LoopObject from "@/loop";
import mountCreep from '@/app/creep'
import mountRoom from '@/app/room'
import mountGlobal from '@/app/global'
import { mountPowerToRoom } from '@/app/powerCreep'
import { mountConsole } from '@/contrib/console'


export default class MainControlLoopObject extends LoopObject {

    /**
     * 初始化存储
     */
    initStorage(): void {
        if (!Memory.rooms) Memory.rooms = {}
        else delete Memory.rooms.undefined

        if (!Memory.resourceSourceMap) Memory.resourceSourceMap = {}
        if (!Memory.waitSpawnCreeps) Memory.waitSpawnCreeps = {}
    }

    born(): void {
        super.born()

        const spawns = Object.values(Game.spawns)
        if (spawns.length > 1) return

        log('欢迎来到 Screeps 的世界!\n', 'hopgoldy bot', Color.Green)
        // 设置中心点位并执行初始化配置
        // setBornCenter(spawns[0])
        // spawns[0].room.controller.onLevelChange(1)
        // spawns[0].room.controller.stateScanner()
    }
    reset(): void {
        super.reset()

        log('重新挂载拓展', 'global', Color.Green)

        this.initStorage()

        // 挂载全部拓展
        mountGlobal()
        mountRoom()
        mountCreep()

        // 挂载 power 能力
        mountPowerToRoom()

        // 挂载命令行
        mountConsole()
    }
    tickStart(): void {
        super.tickStart()
    }
    do(): void {
        super.do()
    }
    afterWork(): void {
        super.afterWork()
    }
    tickEnd(): void {
        super.tickEnd()
    }
}
